package modele;


import java.sql.*;
import java.util.*;
import java.util.Date;
public class BrocanteDAO {
    public static void chargeBrocante(Brocante b) {
        Map <Integer, Type> lesTypes = new TreeMap <Integer, Type> ();
        try {
            Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            
            //1e partie
            ResultSet rs = req.executeQuery("select * from brocante");
            String nombrocante;
            String lieubrocante;
            Date datebrocante;
            rs.next();
            nombrocante = rs.getString("nombrocante");
            lieubrocante = rs.getString("lieubrocante");
            datebrocante = rs.getDate("datebrocante");
            b.setNom(nombrocante);
            b.setLieu(lieubrocante);
            b.setDate(datebrocante);
                     
            
            //2e partie
            ResultSet rs2 = req.executeQuery("select * from type");
            int idType;
            String description;
            int prix;
            Collection <Emplacement> e;
            while ( rs2.next() ) {
                idType = rs2.getInt("idType");
                description = rs2.getString("description");
                prix = rs2.getInt("prix");
                e = new HashSet <Emplacement> ();
                Statement reqP = con.createStatement();
                ResultSet rsP = reqP.executeQuery("select * from emplacement where emplacement.type = " + idType);
                    while (rsP.next()) {
                        Emplacement emp = new Emplacement (rsP.getInt("code"), rsP.getString("nomabonne"));
                        e.add(emp);
                    }
                
                Type t = new Type (idType, description, prix, e);
                b.addType(t);
                
            }
        } catch(SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }
    }
    
    
    
}
